#include ".\ximalist.h"
#include "ximage.h"

CxImageList::CxImageList(void)
{
}

CxImageList::~CxImageList(void)
{
	Free();
}

bool CxImageList::Free()
{
	for (unsigned int i =0; i < m_list.size(); ++i )
	{
		CxImage * pBase = NULL;
		pBase = m_list[i];
		pBase->Destroy();
		delete pBase;
		pBase = 0;
	}

	m_list.clear();

	return TRUE;
}


bool CxImageList::InsertItem( CxImage * pBitmap )
{
	m_list.push_back( pBitmap );

	return TRUE;
}

CxImage * CxImageList::GetItem( int nIndex )
{
	int nCnt = m_list.size();

	if ( nIndex < 0 || nIndex > nCnt -1 )
		return FALSE;

	return m_list[ nIndex ];
}


bool CxImageList::GetFirstItem( CxImage *pBitmap )
{
	if ( m_list.size() == 0 )
	{
		pBitmap = NULL;
		return FALSE;
	}

	m_nIndex = 0;

	pBitmap = (CxImage*) m_list[ m_nIndex ];

	return TRUE;
}

bool CxImageList::GetNextItem( CxImage *pBitmap )
{
	m_nIndex++;

	if ( (int)(m_list.size() -1) < m_nIndex  )
	{
		pBitmap = NULL;
		m_nIndex = -1;
		return FALSE;
	}

	pBitmap = (CxImage*) m_list[ m_nIndex ];

	return TRUE;
}

bool CxImageList::DeleteItem(int idx)
{
	if (  (int)m_list.size() <= idx )
		return FALSE;

//	m_list.delete_item( idx );
	m_list.erase(m_list.begin() + idx);

	return TRUE;
}
